/**
 * Copyright ©2016-2020 northkingbpo Corporation, All Rights Reserved
 * http://www.northkingbpo.net/
 */
package profile.hujia.spring.cloud.seata.storage.service;

import org.springframework.stereotype.Service;
import profile.hujia.spring.cloud.seata.storage.dao.StorageRepository;
import profile.hujia.spring.cloud.seata.storage.domain.StorageEntity;

/**
 * class info
 *
 * @author hujia
 * @date 2019-05-23 14:06
 */
@Service
public class StorageServiceImg implements StorageService {

    private final StorageRepository storageRepository;

    public StorageServiceImg(StorageRepository storageRepository) {
        this.storageRepository = storageRepository;
    }

    @Override
    public void deduct(String commodityCode, int count) {
        StorageEntity storageEntity = storageRepository.findByCommodityCode(commodityCode);
        storageEntity.setCount(storageEntity.getCount() - count);
        storageRepository.save(storageEntity);
    }
}
